package com.zhongjh.app.phone.main

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.zhongjh.app.data.http.service.ShoppingCartApi
import com.zhongjh.app.phone.shoppingcart.shoppingCartCountFlow
import com.zhongjh.mvvmibatis.extend.launchApiFlow
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

/**
 * 产品详情
 * @author zhongjh
 * @date 2022/7/8
 */
@HiltViewModel
class MainViewModel @Inject constructor(private val shoppingCartApi: ShoppingCartApi) :
    ViewModel() {

    /**
     * 初始化获取购物车数量
     */
    fun initShoppingCart() {
        viewModelScope.launch {
            launchApiFlow(shoppingCartCountFlow) {
                // 购物车最新数据
                val shoppingCartCount = shoppingCartApi.shoppingCartCount0()
                shoppingCartCount
            }
        }
    }
}